package org.jetlinks.community.mstn.exception;

import org.hswebframework.web.i18n.LocaleUtils;
import org.jetlinks.core.enums.ErrorCode;

public class MstnAssetsUnknownException  extends RuntimeException {
    private final ErrorCode code;
    private final String message;

    public MstnAssetsUnknownException(ErrorCode errorCode) {
        this(errorCode, errorCode.getText());
    }

    public MstnAssetsUnknownException(ErrorCode errorCode, Throwable cause) {
        super(cause);
        this.code = errorCode;
        this.message = cause.getMessage();
    }

    public MstnAssetsUnknownException(ErrorCode code, String message) {
        this.code = code;
        this.message = message;
    }

    public String getMessage() {
        return this.message == null ? this.code.getText() : this.message;
    }

    public String getLocalizedMessage() {
        return LocaleUtils.resolveMessage(this.getMessage(), new Object[0]);
    }

    public ErrorCode getCode() {
        return this.code;
    }
}
